package top.lshaci.learning.netty.buf;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.util.CharsetUtil;

/**
 * ByteBufTest02
 *
 * @author lshaci
 * @since 1.0.0
 */
public class ByteBufTest02 {

    public static void main(String[] args) {
        ByteBuf byteBuf = Unpooled.copiedBuffer("Hello,World!", CharsetUtil.UTF_8);
        if (byteBuf.hasArray()) {
            final byte[] array = byteBuf.array();
            System.err.println(new String(array, CharsetUtil.UTF_8));
            System.err.println(byteBuf.getClass());

            System.err.println("offset=" + byteBuf.arrayOffset());
            System.err.println("readerIndex=" + byteBuf.readerIndex());
            System.err.println("writerIndex=" + byteBuf.writerIndex());
            System.err.println("可读字节数 => readableBytes=" + byteBuf.readableBytes());
        }
    }
}
